/*
 * @author ${user}
 * @date ${year}-${month}-${day}
 */

package net.xdclass.listener;

import com.rabbitmq.client.Channel;
import lombok.extern.slf4j.Slf4j;
import net.xdclass.enums.BizCodeEnum;
import net.xdclass.exception.BizException;
import net.xdclass.model.EventMessage;
import net.xdclass.service.ProductOrderService;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.annotation.RabbitHandler;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Component
@RabbitListener(queues = "order.close.queue")
@Slf4j
public class ProductOrderMQListener {
	@Autowired
	private ProductOrderService productOrderService;

	@RabbitHandler
	public void productOrderHandler(EventMessage eventMessage, Message message, Channel channel){
      log.info("获取消息${}",message);
      try{
		  productOrderService.closeProductOrder(eventMessage);
	  }catch(Exception e){
       log.error("消息处理报错${}",message);
       throw  new BizException(BizCodeEnum.MQ_CONSUME_EXCEPTION);
	  }


	}
}
